<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :advOptions="[]"
      :dictMap="dictMap"
      :formOptions="formOptions"
      :outputQueryParams="queryParams"
      :queryParams="queryParams"
      :defaultEventKey="defaultEventKey"
      :labelWidth="75"
    ></Ht-search-form>

    <ht-table
      :defaultEventKey="defaultEventKey"
      ref="dataTable"
      :dictMap="dictMap"
      :multi-select="false"
      :opButtonList="opButtonList"
      :queryParams="queryParams"
      :reqConfig="regConfig"
      :showSerialNumber="false"
      :tableBindColumns="tableBindColumns"
    >
      <template v-slot:operate>
        <el-table-column align="left" fixed="right" label="操作" width="120">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      center
      :visible.sync="open"
      v-if="open"
      append-to-body
      width="1024px"
    >
      <el-form ref="detailForm" :model="detailForm" label-width="140px">
        <div slot="header" class="label-header-msg">
          <span></span>
        </div>
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>基本信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="系统流水号" prop="id">
                <el-input v-model="detailForm.id" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="报文标识号" prop="pkgId">
                <el-input v-model="detailForm.pkgId" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="CPG日期" prop="vdate">
                <el-date-picker
                  v-model="detailForm.vdate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工作日期" prop="workdate">
                <el-date-picker
                  v-model="detailForm.workdate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="转发日期" prop="npcSndDate">
                <el-date-picker
                  v-model="detailForm.npcSndDate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="回执期限" prop="returnDate">
                <el-input v-model="detailForm.returnDate" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="货币种类" prop="curcd">
                <el-input v-model="detailForm.curcd" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="总金额" prop="totAmount">
                <ht-amount-input v-model="detailForm.totAmount" placeholder="总金额" :disable="true"></ht-amount-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="付款人数目" prop="payerNum">
                <el-input v-model="detailForm.payerNum" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="业务类型" prop="bizTypeCode">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.bizTypeCode === null || detailForm.bizTypeCode === undefined
                      ? ''
                      : detailForm.bizTypeCode + '-' + detailForm.bizTypeCodeDesc
                  "
                  placeholder="业务类型"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="报文接收时间" prop="rcvTime">
                <el-date-picker
                  style="width: 100%"
                  v-model="detailForm.rcvTime"
                  value-format="yyyyMMddHHmmss"
                  type="datetime"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>收款方信息</span>
          </div>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="收款行行号" prop="payeeBrno">
                <el-input v-model="detailForm.payeeBrno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="收款行行名" prop="payeeBrname">
                <el-input v-model="detailForm.payeeBrname" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="收款人账号" prop="payeeActno">
                <el-input v-model="detailForm.payeeActno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="收款人名称" prop="payeeName">
                <el-input v-model="detailForm.payeeName" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <div class="discountReceipt-pick-operate-box">
          <div class="operate-box-bottom">
            <div class="bottom-content">
              <ht-table
                ref="returndataTable"
                :multi-select="false"
                :showSerialNumber="false"
                :dictMap="dictMap"
                :queryParams="queryDetailParams"
                :tableBindColumns="tableBindDetailColumns"
                :opButtonList="opButtonList"
                :reqConfig="regConfigDetail"
                :showRightToolbar="false"
                :showPagination="false"
              >
                <template v-slot:operate>
                  <el-table-column align="left" fixed="right" label="操作" width="120">
                    <template slot-scope="scope">
                      <ht-button-group
                        :buttonList="[
                      {
                        label: '回执',
                        visible: !(scope.row.bizStatus === undefined || scope.row.bizStatus === null
                          ? false
                          : scope.row.bizStatus !== ''),
                        doFunc: () => {
                          returnReceipt(scope.$index, scope.row);
                        },
                      },
                    ]"
                      />
                    </template>
                  </el-table-column>
                </template>
              </ht-table>
            </div>
          </div>
        </div>
<!--
          <div class="discountReceipt-pick-operate-box">
            <div class="operate-box-bottom">
              <div class="bottom-content">
          <el-table
            :data="detailTableData"
            style="width: 100%"
            height="100%"
            size="mini"
            highlight-current-row
          >
            <el-table-column prop="dtlNo" label="明细标识号" width="140" sortable show-overflow-tooltip></el-table-column>
            <el-table-column prop="payerActno" label="付款人账号" width="160" sortable show-overflow-tooltip></el-table-column>
            <el-table-column prop="payerName" label="付款人户名" width="120" sortable show-overflow-tooltip></el-table-column>
            <el-table-column prop="payerBrno" label="付款行行号" width="120" sortable show-overflow-tooltip></el-table-column>
            <el-table-column prop="amount" label="金额" width="120" sortable show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.amount | toThousands}}
              </template>
            </el-table-column>
            <el-table-column prop="bizCtgyCode" label="业务种类编码" width="140" sortable show-overflow-tooltip>
              <template slot-scope="scope">
               {{scope.row.bizCtgyCode | dictFilter(dictMap.BIZ_CTGY_BEPS_E102)}}
              </template>
            </el-table-column>
            <el-table-column prop="bizStatus" label="业务状态" show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.bizStatus | dictFilter(dictMap.BIZRT_STATUS)}}
              </template>
            </el-table-column>
            <el-table-column
              fixed="right"
              label="操作"
              width="100">
              <template slot-scope="scope">
                <el-button v-if="scope.row.bizStatus === undefined"
                           @click="returnReceipt(scope.$index, scope.row)" type="text" size="small">回执</el-button>
              </template>
            </el-table-column>
          </el-table>
              </div>
            </div>
          </div>-->
      </el-form>

      <div slot="footer" align="center" class="dialog-footer">
        <el-button type="primary" @click="save">提 交</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :close-on-click-modal="false"
      :title="title1"
      :visible.sync="open1"
      v-if="open1"
      append-to-body
      width="1024px"
    >
      <el-form ref="detailForm1" :model="detailForm1" :rules="returnrules" label-width="140px">
        <div slot="header" class="label-header-msg">
          <span></span>
        </div>
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="明细标识号" prop="dtlNo">
              <el-input v-model="detailForm1.dtlNo" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="业务状态" prop="bizStatus">
              <el-select style="width: 100%" v-model="detailForm1.bizStatus" placeholder="业务状态">
                <el-option
                  v-for="dict in dictMap.BIZRT_STATUS"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <div v-if="this.detailForm1.bizStatus === 'PR09'">
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="业务拒绝处理码" prop="bizRejectCode">
                <el-select style="width: 100%" v-model="detailForm1.bizRejectCode" placeholder="业务拒绝处理码">
                  <el-option
                    v-for="dict in dictMap.CIS_CODE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="业务拒绝信息" prop="bizRejectInfo">
                <el-input type="textarea" v-model="detailForm1.bizRejectInfo" maxlength="105" show-word-limit />
              </el-form-item>
            </el-col>
          </el-row>
        </div>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="附言" prop="remarks">
              <el-input type="textarea" v-model="detailForm1.remarks" maxlength="256" show-word-limit />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" align="center" class="dialog-footer">
        <el-button type="primary" @click="returnSubmit(detailForm1.index)">提 交</el-button>
        <el-button type="primary" @click="cancel1">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  apiUrlConfigEntry,
  apiUrlConfigEntryDetail,
  batchCollectionReceiptEntryDetail,
  batchCollectionReceiptEntrySave,
  // batchCollectionReceiptEntryDetailSearch
} from "@/api/cnaps/beps/381";
import { listPageMixin } from "@/libs/listPageMixin";
import HtAmountInput from "@/views/components/HtAmountInput";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";
import { stopPayAnswerQueryDetail } from "@/api/cnaps/beps/412";
import {BatchCustsSignPtlMgtRspEntrySave, datchCustsSignPtlMgtRspEntryDetailQuery} from "@/api/cnaps/beps/393";
export default {
  name: "BatchCollectionReceiptEntry",
  mixins: [listPageMixin],
  components: {HtAmountInput},
  data() {
    return {
      defaultEventKey: "defaultEventKey",
      // 查询参数
      queryParams: {
        vdate: "",
        vdate1: "",
        workdate: "",
        workdate1: "",
        id: "",
        payeeActno: "",
        batchNo: "",
      },
      queryDetailParams: {
        id: undefined,
      },

      // 搜索
      formOptions: [],
      //
      searchFormDictList: [
        "DRCTCODE",
        "Acc_Chg_Flg_Code",
        "PROCESSSTATUS",
        "PKG_STATUS",
        "BIZ_CTGY_BEPS_E102",
        "BIZRT_STATUS",
        "CIS_CODE",
      ],
      // 列信息
      regConfig: apiUrlConfigEntry,
      //明细表信息
      regConfigDetail: apiUrlConfigEntryDetail,

      tableBindColumns: [
        { prop: "id", label: "交易流水号", width: 180 },
        { prop: "pkgId", label: "报文标识号", width: 180 },
        { prop: "vdate", label: "CPG日期", type: "date", width: 120 },
        { prop: "workdate", label: "工作日期", type: "date", width: 120 },
        { prop: "batchNo", label: "批序号", width: 120 },
        { prop: "payeeActno", label: "收款人账号", width: 180 },
        { prop: "totAmount", label: "总金额", type: "price", width: 120 },
        { prop: "rcvTime", label: "报文接收时间", type: "date", width: 180 },
      ],

      tableBindDetailColumns: [
        { prop: "dtlNo", label: "明细标识号", width: 160 },
        { prop: "payerActno", label: "付款人账号", width: 160 },
        { prop: "payerName", label: "付款人户名", width: 120 },
        { prop: "payerBrno", label: "付款行行号", width: 120 },
        { prop: "amount", label: "金额", type: "price", width: 120 },
        { prop: "bizCtgyCode", label: "业务种类编码", dictCode: "BIZ_CTGY_BEPS_E102", width: 120 },
        { prop: "bizStatus", label: "业务状态", dictCode: "BIZRT_STATUS"},
      ],

      dictMapAsync: {},
      // 弹出层标题
      title: "",
      detailTableData:[],
      title1: undefined,
      // 是否显示弹出层
      open: false,
      open1: false,
      // 表单参数
      detailForm: {
        returnList: [],
      },
      detailForm1: {
        dtlNo: undefined,
        bizStatus: undefined,
        bizRejectCode: undefined,
        bizRejectInfo: undefined,
        remarks: undefined,
      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,

      returnrules: {
        bizStatus: [{ required: true, message: "请输入业务状态", trigger: "blur" }],
        bizRejectCode: [{ required: true, message: "请输入业务拒绝处理码", trigger: "blur" }],
        bizRejectInfo: [{ max: 105, message: "最大长度位105位", trigger: "blur" }],
        remarks: [{ max: 256, message: "最大长度位105位", trigger: "blur" }],
      },
    };
  },
  mounted() {
    const formOptions = [
      // 普通搜索

      {
        type: "dates",
        nameObj: {
          startTimeName: "vdate",
          endTimeName: "vdate1",
        },
        defaultAttr: {
          size: "small",
          label: "CPG日期",
          placeholder: ["请输入CPG开始日期", "请输入CPG结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },

      {
        type: "dates",
        nameObj: {
          startTimeName: "workdate",
          endTimeName: "workdate1",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作开始日期", "请输入工作结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },

      {
        type: "input",
        prop: "id",
        defaultAttr: {
          size: "small",
          label: "交易流水号",
          placeholder: "请输入交易流水号",
        },
      },

      {
        type: "input",
        prop: "payeeActno",
        defaultAttr: {
          size: "small",
          label: "收款人账号",
          placeholder: "请输入收款人账号",
        },
      },

      {
        type: "input",
        prop: "batchNo",
        defaultAttr: {
          size: "small",
          label: "批序号",
          placeholder: "请输入批序号",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */

    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    cancel1() {
      this.open1 = false;
    },
    // detailSearch(id) {
    //   batchCollectionReceiptEntryDetailSearch(id).then((res) => {
    //     this.detailTableData = res.result.data;
    //   });
    // },
    /** 详情按钮操作 */
    handleDetail(row) {
      batchCollectionReceiptEntryDetail(row).then((response) => {
        this.title = "批量代收业务回执报文录入明细";
        this.detailForm = response.result;
        this.queryDetailParams.id = response.result.id;
        // this.detailSearch(this.queryDetailParams.id)
        this.open = true;
      });
    },
    // 回执详情
    returnReceipt(index, row) {
      this.title1 = "回执信息";
      this.detailForm1 = Object.assign({}, row); //将数据传入dialog页面
      this.detailForm1.index = index; //传递当前index
      this.open1 = true;
    },

    returnSubmit(index) {

      this.$refs["detailForm1"].validate((valid) => {

        if (valid) {
          this.$refs.returndataTable.dataList[index].bizStatus = this.detailForm1.bizStatus;
          this.$refs.returndataTable.dataList[index].bizRejectCode = this.detailForm1.bizRejectCode;
          this.$refs.returndataTable.dataList[index].bizRejectInfo = this.detailForm1.bizRejectInfo;
          this.$refs.returndataTable.dataList[index].remarks = this.detailForm1.remarks;
          var value = this.$refs.returndataTable.dataList[index];
          this.$set(this.$refs.returndataTable.dataList, index, value);
          this.open1 = false;
        }
      });
    },

    //页面提交按钮
    save() {
      this.detailForm.returnList = this.$refs.returndataTable.dataList;

      for (let i = 0; i < this.detailForm.returnList.length; i++) {
        let bizStatus = this.detailForm.returnList[i].bizStatus;
        if (bizStatus === null || bizStatus === undefined) {
          this.msgError("请处理完所有业务后再提交！");
          return;
        }
      }
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          batchCollectionReceiptEntrySave(this.detailForm)
            .then((res) => {
              this.loading = true;
              this.msgSuccess("提交成功");
              this.open = false;
              this.loading = false;
              this.$alert(`CORE_ID: ${res.result.rspId}`, "生成交易流水号", {
                confirmButtonText: "确定",
                callback: (action) => {
                },
              });
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
  },
};
</script>
